package Code;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class QuestionNum_25_2 {
        public static void main(String[] args) throws IOException {
            makePro();
            setScore();
        }

        /*
         *   (2)使用IO字节流对象和Properties类结合使用,将配置文件中的score键的值修改为100
         */
        public static void setScore() throws IOException{
            FileInputStream fos = new FileInputStream("C:\\360Downloads\\1\\config.properties");
            Properties pro = new Properties();
            pro.load(fos);
            System.out.println("未改数据之前的properties文件内容: "+pro);
            pro.setProperty("score","100");
            fos.close();
            System.out.println("改了数据之后的properties文件内容: "+pro);
        }


        /*
         *  创建配置文件 config.properties,并写入三个键值对
         *  name=zhangsan
         *  score=80
         *  address=beijing
         */
        public static void makePro() throws IOException{
            FileOutputStream fos = new FileOutputStream("C:\\360Downloads\\1\\config.properties");
            Properties pro = new Properties();
            pro.setProperty("name","zhangsan");
            pro.setProperty("score","80");
            pro.setProperty("address","beijing");

            pro.store(fos, "");
            fos.close();
        }
}
